package org.budo.sms.service.yunxun;

import java.util.Map;

import org.budo.support.http.client.Request;
import org.budo.support.http.client.Response;
import org.budo.support.java.net.util.UrlEncodeUtil;
import org.budo.time.Time;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
@Getter
@Setter
public class BudoYunxunSmsServiceImpl implements BudoYunxunSmsService {
    private static final String API_URL = "http://47.93.91.39:18002/send.do";

    private static final String TIME_FORMAT = "yyyyMMddHHmmss";

    private String uid;

    private String pw;

    public String sendSms(String to, String template, Map<String, Object> parameters) {
        String _sign = (String) parameters.get("sign");

        Request request = new Request();
        request.setUrl(API_URL);

        request.setParameter("uid", this.getUid());
        request.setParameter("pw", this.getPw());
        request.setParameter("mb", to);
        request.setParameter("ms", UrlEncodeUtil.encode(_sign + template));
        request.setParameter("tm", Time.now().toString(TIME_FORMAT));

        Response response = request.execute();
        log.info("#43 response=" + response + ", request=" + request);

        return response + "";
    }
}